package com.cy1;

import jdk.swing.interop.SwingInterOpUtils;

public class ArrayDemo {
    public static void main(String[] args) {
        int[] array = {25, 56, 78, 956, 45};
        System.out.println("初始顺序：" + arrayToString(array));

        order(array);

    }

    public static int[] order(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }

            }
            System.out.println("第" + (i + 1) + "次排序：" + arrayToString(array));
        }

        return array;
    }

    public static String arrayToString(int[] array) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < array.length; i++) {
            if (i == array.length - 1) {
                sb.append(array[i]);
            } else {
                sb.append(array[i]).append(",");
            }
        }
        sb.append("]");

        return  sb.toString();
    }
}
